// hyb_yl/backstageServices/pages/yearcardlist/yearcardlist.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tablist: ["全部", "待付款", "服务中", "已过期"],
    currentData: 0,
    list:[],
    page:0,
    pagesize:10
  },
  // 点击切换，滑块index赋值
  checkCurrent: function (e) {
    this.setData({
      currentData: e.currentTarget.dataset.current,
      page:0,
      list:[]
    })
    this.getList();
  },
  carddetail(){
    if (this.data.currentData == 1){
      wx.navigateTo({
        url: '../yearcard/yearcard',
      })
    }else{
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye',
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#ffffff",
    })
    this.getList();
  },
  pay:function(e){
    var that = this;
    var zid = e.currentTarget.dataset.zid;
    var id = e.currentTarget.dataset.id;
    var yid = e.currentTarget.dataset.yid;
    var money = e.currentTarget.dataset.money;
    var wz_num = e.currentTarget.dataset.wz_num;
    var wz_zhekou = e.currentTarget.dataset.wz_zhekou;
    var jd_num = e.currentTarget.dataset.jd_num;
    var hh_num = e.currentTarget.dataset.hh_num;
    var times = e.currentTarget.dataset.times;
    var openid = wx.getStorageSync('openid');
    var ordersn = e.currentTarget.dataset.ordersn;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.user_blyear",
      data: {
        zid: zid,
        yid: yid,
        openid: openid,
        money: money,
        wz_num: wz_num,
        wz_zhekou: wz_zhekou,
        jd_num: jd_num,
        hh_num: hh_num,
        times: times
      },
      success: function (res) {
        var created = res.data.created;
        if (money > '0.00' && money != '') {
          app.util.request({
            'url': "entry/wxapp/zhuanjia.pay_year",
            header: {
              "Content-Type": "application/xml"
            },
            method: "GET",
            data: {
              openid: openid,
              created: created,
              money: money,
              ordersn:ordersn,
              id:id
            },
            success: function (res) {
              wx.requestPayment({
                'timeStamp': res.data.timeStamp,
                'nonceStr': res.data.nonceStr, //字符串随机数
                'package': res.data.package,
                'signType': res.data.signType,
                'paySign': res.data.paySign,
                success: function (res) {
                  wx.showModal({
                    title: '提示',
                    content: "办理成功",
                    success: function (con) {
                      if (con.confirm) {
                        wx.switchTab({
                          url: '/hyb_yl/tabBar/index/index',
                        })
                      }
                    }
                  })
                },
                fail: function (res) {
                  console.log(res)
                }
              })
            }
          })
        }else{
          wx.showModal({
            title: '提示',
            content: "办理成功",
            success: function (con) {
              if (con.confirm) {
                wx.reLaunch({
                  url: '/hyb_yl/tabBar/index/index',
                })
              }
            }
          })
        }

      }
    })
  },
  getList:function(){
    var that = this;
    var type = that.data.currentData;
    app.util.request({
      url: 'entry/wxapp/user.user_yearcard',
      data:{
        openid:wx.getStorageSync('openid'),
        page:that.data.page,
        pagesize:that.data.pagesize,
        type:type
      },
      success:function(res)
      {
        var page = that.data.page + 1;
        that.setData({
          page:page,
          list:that.data.list.concat(res.data)
        })
      }

    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})